#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stdlib.h>

int main()
{
    extern char** environ;
    pid_t id = fork();
    if(id == 0)
    {
        // char* const myargv[] = {"ls", "-a", "-l", NULL};
         char* const myargv[] = {"otherExe", "-a", "-b","-c", NULL};
         char* const myenviron[] = {
             "MYVAL=999",
             "MYPATH=/usr/bin/xxx",
             NULL
         };
         printf("before, pid:%d, ppid:%d\n", getpid(), getppid());

        //execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
        //execlp("ls", "ls", "-a", "-l", NULL);
        //execv("/usr/bin/ls", myargv); 
        //execl("./otherExe", "otherExe", NULL); 
        //putenv("PRIVATE_ENV=999999");
        //execv("./otherExe", myargv);
        //execle("./otherExe", "otherExe", "-a", "-b", "-c", NULL, environ);
         execle("./otherExe", "otherExe", "-a", "-b", "-c", NULL, myenviron);
         printf("after, pid:%d, ppid:%d\n", getpid(), getppid());
         exit(0);
    }

    pid_t ret = waitpid(id, NULL, 0);

    if(ret == id)  printf("wait success\n");
    else  printf("wait fail\n");
    return 0;
}
